#!/usr/bin/python

# See http://prowl.weks.net/ and http://github.com/babs/pyrowl.

# chmod +x this and put a symbolic link (with the suggested name "pushn"
# in your path), and then you can append ";pushn -e 'Event' -d 'Description'"
# to a slow command (like make) to receive a push notification on your
# iPhone when it completes.

import pyrowl

from optparse import OptionParser
from pprint import pprint
import sys

MY_NAME = 'pushn.py'

API_KEY = 'INSERT YOUR API KEY HERE'

usage = "Usage: %prog --event='Event name' --description='Event description'" \
        "\n\n" \
        "Send a push notification to my iPhone."
        
parser = OptionParser(usage=usage)
parser.add_option('-e', '--event',
                  help='name of push notification event')
parser.add_option('-d', '--description',
                  help='contents of push notification')
options, args = parser.parse_args()

if not options.event or not options.description:
    parser.print_help()
    sys.exit(1)

prowl = pyrowl.Pyrowl(API_KEY)

results = prowl.push(application=MY_NAME,
                     event=options.event,
                     description=options.description)

if results[API_KEY].get('type') != u'success':
    pprint(results)
    sys.exit(1)

